
	$(document).ready(function(){
		showAllBook();
		
		
	});
	
	
	
	
	function showAllBook(){
		$.ajax({
			"url":"/springMVCBookms20170807/book/showAllBook",
			"type":"get",
			"success":function(data){
				var result=data;
				for(var i=0;i<result.length;i++){
					var target=$("#book");
					$("<tr id="+result[i].bookid+"><td>"+result[i].bookid+"</td><td>"+
					  result[i].bookname+"</td><td>"+result[i].author+"</td><td>"+
					  result[i].price+"</td><td><button onclick=\"deletebook('"+result[i].bookid+"')\">Delete</button></td>" +
					  		"<td><button onclick=\"updatebook('"+result[i].bookid+"')\" data-toggle='modal' data-target='#myModal'>Update</button></td></tr>").appendTo(target);
				}
			}
		});
	}
	
	
	function deletebook(bookid){
		console.log(bookid);
		$.ajax({
			"url":"/springMVCBookms20170807/book/"+bookid,
			"type":"delete",
			"success":function(data){
				$("#book").html('');
				showAllBook();
			}
			
		});
	}
	
	function updatebook(bookid){
		var h="#"+bookid;
		var id=$(h).children().get(0).innerHTML;
		var bookname=$(h).children().get(1).innerHTML;
		var author=$(h).children().get(2).innerHTML;
		var price=$(h).children().get(3).innerHTML;
		
		$("#bookid").val(id);
		$("#bookname").val(bookname);
		$("#author").val(author);
		$("#price").val(price);
		
		
		
	}
	